package cn.wen.core.titlebar.base;

import android.app.Activity;
import android.util.SparseArray;
import android.view.View;
import android.view.ViewGroup;

/**
 * APP标题构建的抽象基类
 */

public abstract class BaseBarBuild<B extends BaseTitleBar> {
    /**
     * 标题添加到的父布局
     */
    protected ViewGroup mParent;
    protected SparseArray<CharSequence> mTexts = new SparseArray<>();
    protected SparseArray<View.OnClickListener> mClicks = new SparseArray<>();
    /**
     * Activity
     */
    public Activity mActivity;

    public BaseBarBuild(Activity activity) {
        this(activity, null);
    }

    public BaseBarBuild(Activity activity, ViewGroup parent) {
        mParent = parent;
        mActivity = activity;
    }

    /**
     * 标题
     */
    protected abstract B getTitleBar();

    /**
     * 构建标题
     */
    public B build() {
        B titleBar = getTitleBar();
        if (titleBar != null) {
            titleBar.apply();
        }
        return titleBar;
    }

    public void setText(int viewId, CharSequence text) {
        mTexts.put(viewId, text);
    }


    public void setOnClickListener(int viewId, View.OnClickListener listener) {
        mClicks.put(viewId, listener);
    }
}
